<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>维护页面</title>
    <link rel="stylesheet" href="/res/layui/css/layui.css"  media="all">
    <script src="/res/js/jquery-3.4.1.min.js"></script>
    <script src="/res/js/tools.js"></script>
</head>
<body>
<form class="layui-form" action="" lay-filter="example" id="myForm">
    <input type="hidden" name="lid">
    <div class="layui-form-item">
        <label class="layui-form-label">类型名称</label>
        <div class="layui-input-inline">
            <input type="text" name="lname" required lay-verify="required|fName" placeholder="请输入鲜花名字" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">类型说明</label>
        <div class="layui-input-inline">
            <input type="text" name="lremark" required lay-verify="required|number" placeholder="请输入鲜花价格" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
            <button type="button" class="layui-btn layui-btn-primary" onclick="parent.layer.closeAll()">关闭</button>
        </div>
    </div>
</form>
<script src="/res/layui/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'layedit', 'laydate'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate;
        var $=layui.$;

        //监听提交
        form.on('submit(formDemo)', function(data){
            // let forData=new FormData(document.getElementById("myForm"));
            // layer.alert(JSON.stringify(data.field), {
            //     title: '最终的提交信息'
            // });
            //没有文件上传时提交表单的代码
            let url="/lvTb/addOrUpdate";
            let date=data.field;//需要提交的数据
            console.log(data);
            $.post(url,date,function (resp){
                    if (resp.state=="1"){
                        //在子页面调用父页面的方法
                        parent.closeLayer(resp.msg);
                    }else{
                        layer.msg(resp.msg);
                    }
            },"json");
            return false;
        });
        setFormValue();

        function setFormValue(){
            let flId = getQueryString("id");
            if(flId){ //flId==""  flId==null  flId==undefined
                let url_ = "/lvTb/selectOne";
                let data_ = {id:flId};
                $.post(url_,data_,function (resp) {
                    console.info(resp);
                    if(resp.state=="1"){
                        //给表单赋值
                        form.val('example', resp.data);
                    }
                },"json")
            }

        }



    });

</script>
</body>
</html>